#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <dirent.h>
#include <locale.h>
#include <langinfo.h>
#include <iconv.h>
#include <signal.h>
#include <stdarg.h>
#include <ncurses.h>

int cmus_running = 1;
int ui_initialized = 0;

//handlers
static int ctrl_c_pressed = 0;

static void 
sig_int(int sig) {
    ctrl_c_pressed = 1;
}

static void 
sig_hup(int sig) {
    cmus_running = 0;
}

static int needs_to_resize = 1;

static void 
sig_winch(int sig) {
    needs_to_resize = 1;
}


void 
init_ncurses(void) {
    
	struct sigaction act;
    char *ptr, *term;

    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    act.sa_handler = sig_int;
    sigaction(SIGINT, &act, NULL);

    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    act.sa_handler = sig_hup;
    sigaction(SIGHUP, &act, NULL);

    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    act.sa_handler = SIG_IGN;
    sigaction(SIGPIPE, &act, NULL);

    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    act.sa_handler = sig_winch;
    sigaction(SIGWINCH, &act, NULL);

    initscr();

    cbreak();
	noecho();	
	keypad(stdscr, TRUE);
	start_color();
	curs_set(0);

	init_pair(1,COLOR_RED,COLOR_BLACK);
	init_pair(2,COLOR_WHITE,COLOR_BLUE);
	init_pair(3,COLOR_BLUE,COLOR_WHITE);

	bkgd(COLOR_PAIR(3));

	WINDOW *dialogo;
	WINDOW *master;
	master = subwin(stdscr, LINES, COLS, 0, 0);
//	wborder(master, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,0, 0, 0, 0);
	dialogo = subwin(master, 5, 30, 8, 2);
//	dialogo= newwin (7,80,7,17);

	wbkgd(dialogo, COLOR_PAIR(1));
    box(dialogo, ACS_VLINE, ACS_HLINE); 
    
	mvwprintw(master, 1, 3, BANNER); 

	wborder(master, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,0, 0, 0, 0);

	mvwaddstr(master, 0, 4, " papaya media streamer "); 

	mvwprintw(dialogo, 0, 4, " active input sources ");
	mvwprintw(dialogo, 1, 2, "%s", "test test test");	
    //mvwprintw(dialogo,2,3,"yo, ora papaya aspetta che je aumenti er volume se no nun se sente ncazzo");
    //mvwprintw(dialogo,4,12,"premi pag-up per aumetarlo");
    
	refresh(); 
	wgetch(dialogo);
      
     delwin(dialogo);
	 erase(); 
     refresh(); 
 	endwin();
 
}


